unit FFonts;

interface
uses
	Windows, Graphics, OpenGL, FBase, FGLFont;

type
	TFontSize = Record
		x : single;
		y : single;
	end;

var
	gFontSizes      : array[0..1023] of TFontSize;    // Buffer for character size information
	gFontList       : integer;                        // Handle to character display lists
	GLFont: TGLFont;

procedure glPrint(text : pchar; size : integer; ui : boolean = true);
procedure glCreateFont();

implementation

procedure glCreateFont();
var
	Font : Cardinal;
begin
//	gFontList:= glGenLists(256);
//		Font := CreateFont(  -24,
//													0,
//													0,
//													0,
//													0,    // FW_BOLD
//													0,
//													0,
//													0,
//													ANSI_CHARSET,
//													OUT_TT_PRECIS,
//													CLIP_DEFAULT_PRECIS,
//													ANTIALIASED_QUALITY,
//													FF_DONTCARE or DEFAULT_PITCH,
//													'Thorndale AMT');
//	SelectObject(dc, Font);

	// Create display lists for each character in the font:
//	wglUseFontOutlines(dc,                 // Device context of font -source-
//										 0,                  // First character
//										 256,                // Number of characters
//										 gFontList,          // Handle of font display lists
//										 0,                  // This is the sampling tolerance. Higher values create less detailed outlines.
//										 0,                  // This is the extrusion depth.
//										 WGL_FONT_POLYGONS,  // What kind of output? You can also use WGL_FONT_LINES
//										 @gFontSizes);       // Array to store info about character sizes
//	wglUseFontBitmaps(dc, 0, 256, gFontList);
	glFontCreate( @GLfont, 'Fonts/THOWR___.glf' );
end;

procedure glPrintText(text : pchar; size : integer; ui : boolean = true);
begin
	glPushMatrix();
	size := 256;

	if ui then begin
//		glTranslatef(0, 2*size div 3, 0);
		glScalef(size, -size, size)
	end else begin
		glScalef(size, size, size);
	end;

	glListBase(gFontList);


	glEnable(GL_TEXTURE_2D);
	 glEnable (GL_BLEND);
	 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//	 glEnable (GL_POLYGON_SMOOTH);
//	 glHint (GL_POLYGON_SMOOTH_HINT, GL_DONT_CARE);

//	glCallLists(Length(text), GL_UNSIGNED_BYTE,	@text[0]);

	glFontBegin( @GLFont );
	glFontTextOut( text, 0, 0, 0 );
	glFontEnd( );

	glDisable(GL_BLEND);

	glPopMatrix();

end;

procedure glPrint(text : pchar; size : integer; ui : boolean = true);
var
	color : array[1..4] of GLFloat;
begin
	if ui then begin
		GlGetFloatv(GL_CURRENT_COLOR, @color);
		glPrintText(text, size, ui);
		glColor3f(0, 0, 0);
		glTranslatef(10, 10, 0);
	end;
	glPrintText(text, size, ui);

	if ui then
		glColor3f(color[1], color[2], color[3]);
end;

end.

